import Vue from "vue";
import VueRouter, { RouteConfig } from "vue-router";
import NProgress from "nprogress"; //进度条插件
import "nprogress/nprogress.css";

Vue.use(VueRouter);

const routes: Array<RouteConfig> = [
  {
    path: "/",
    name: "container",
    component: () => import("@/views/container.vue"),
    children: [
      // 实时监测
      {
        path: "realtime-monitor",
        name: "realtime-monitor",
        component: () =>
          import("@/views/content/realtime-monitor/realtime-monitor.vue"),
        meta: {
          title: "实时监测",
        },
        children: [
          {
            path: "system-status",
            name: "system-status",
            component: () =>
              import(
                "@/views/content/realtime-monitor/system-status/system-status-index.vue"
              ),
            meta: {
              title: "系统状态",
            },
          },
          {
            path: "network-activity",
            name: "network-activity",
            component: () =>
              import(
                "@/views/content/realtime-monitor/network-activity/network-activity-index.vue"
              ),
            meta: {
              title: "网络活动",
            },
          },
          {
            path: "interface-flow",
            name: "interface-flow",
            component: () =>
              import(
                "@/views/content/realtime-monitor/interface-flow/interface-flow-index.vue"
              ),
            meta: {
              title: "接口流量",
            },
          },
          // 默认路由
          {
            path: "",
            redirect: (to) => {
              return "/realtime-monitor/system-status";
            },
          },
        ],
      },
      // 日志审计
      {
        path: "log-audit",
        name: "log-audit",
        component: () => import("@/views/content/log-audit/log-audit.vue"),
        meta: {
          title: "日志审计",
        },
      },
      // 统计报表
      {
        path: "statistic-statement",
        name: "statistic-statement",
        component: () =>
          import("@/views/content/statistic-statement/statistic-statement.vue"),
        meta: {
          title: "统计报表",
        },
      },
      //行为管理
      {
        path: "behavior-manage",
        name: "behavior-manage",
        component: () =>
          import("@/views/content/behavior-manage/behavior-manage.vue"),
        meta: {
          title: "行为管理",
        },
      },
      // 用户管理
      {
        path: "user-manage",
        name: "user-manage",
        component: () => import("@/views/content/user-manage/user-manage.vue"),
        meta: {
          title: "用户管理",
        },
        children: [
          {
            path: "user-manage",
            name: "user-manage",
            component: () =>
              import(
                "@/views/content/user-manage/user-manage/user-manage-index.vue"
              ),
            meta: {
              title: "用户管理",
            },
          },
          {
            path: "transparent-identity-config",
            name: "transparent-identity-config",
            component: () =>
              import(
                "@/views/content/user-manage/certificate-config/transparent-identity-config/transparent-identity-config-index.vue"
              ),
            meta: {
              title: "透明识别配置",
            },
          },
          {
            path: "group-config",
            name: "group-config",
            component: () =>
              import(
                "@/views/content/user-manage/group-config/group-config-index.vue"
              ),
            meta: {
              title: "分组配置",
            },
          },
          // 默认路由
          {
            path: "",
            redirect: (to) => {
              return "/user-manage/user-manage";
            },
          },
        ],
      },
      // 系统管理
      {
        path: "system-manage",
        name: "system-manage",
        component: () =>
          import("@/views/content/system-manage/system-manage.vue"),
        meta: {
          title: "系统管理",
        },
        children: [
          {
            path: "admin-config",
            name: "admin-config",
            component: () =>
              import(
                "@/views/content/system-manage/admin-config/admin-config-index.vue"
              ),
            meta: {
              title: "管理员配置",
            },
          },
          {
            path: "network-config",
            name: "network-config",
            component: () =>
              import(
                "@/views/content/system-manage/network-config/network-config-index.vue"
              ),
            meta: {
              title: "网络配置",
            },
          },
          {
            path: "system-config",
            name: "system-config",
            component: () =>
              import(
                "@/views/content/system-manage/system-config/system-config-index.vue"
              ),
            meta: {
              title: "系统配置",
            },
          },
          {
            path: "ps-platform-config",
            name: "ps-platform-config",
            component: () =>
              import(
                "@/views/content/system-manage/ps-platform-config/ps-platform-config-index.vue"
              ),
            meta: {
              title: "公安平台配置",
            },
          },
          {
            path: "product-regist",
            name: "product-regist",
            component: () =>
              import(
                "@/views/content/system-manage/product-regist/product-regist-index.vue"
              ),
            meta: {
              title: "产品注册",
            },
          },
          // 系统日志下的邮件日志与操作日志
          {
            path: "email-log",
            name: "email-log",
            component: () =>
              import(
                "@/views/content/system-manage/system-log/email-log/email-log-index.vue"
              ),
            meta: {
              title: "邮件日志",
            },
          },
          {
            path: "operate-log",
            name: "operate-log",
            component: () =>
              import(
                "@/views/content/system-manage/system-log/operate-log/operate-log-index.vue"
              ),
            meta: {
              title: "操作日志",
            },
          },
          // 默认路径。重定向到当前一级菜单下第一个子路由即可
          {
            path: "",
            redirect: (to) => {
              return "/system-manage/admin-config";
            },
          },
        ],
      },
      // 默认路由
      {
        path: "",
        redirect: (to) => {
          return "/realtime-monitor";
        },
      },
      // 404页面
      {
        path: "404",
        name: "404",
        component: () => import("@/views/content/feedback/404.vue"),
      },
      // 匹配所有地址栏乱输入的，重定向到404
      {
        path: "/:pathMatch(.*)",
        redirect: (to) => {
          return "404";
        },
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
});

router.afterEach((to, from) => {
  NProgress.done();
});

export default router;
